package com.bookmngsys.View;


import com.bookmngsys.entity.BookInfo;
import lombok.Getter;
import lombok.Setter;
import springfox.documentation.spring.web.json.Json;

/**
 * @author Administrator
 */
@Getter
@Setter
public class TempDto {
    private int bookId;

    private String isbn;
    private String barcode;

    private Integer reserveReaderId;
    private Long reserveDate;
    private Integer borrowReaderId;
    private Long borrowDate;
    private Long returnDate;
    private Float fine = 0.0f;
    private int isBorrow;
    private int isReserve;
    private int damage;
    private int lost;

    public static TempDto convert(BookInfo bookInfo){

        TempDto tempDto = new TempDto();
        tempDto.setBookId(bookInfo.getBookId());
        tempDto.setIsbn(bookInfo.getIsbn());
        tempDto.setBarcode(bookInfo.getBarcode());
        tempDto.setReserveDate(bookInfo.getReserveDate());
        tempDto.setReserveReaderId(bookInfo.getReserveReaderId());
        tempDto.setBorrowDate(bookInfo.getBorrowDate());
        tempDto.setReturnDate(bookInfo.getReturnDate());
        tempDto.setBorrowReaderId(bookInfo.getBorrowReaderId());
        tempDto.setFine(bookInfo.getFine());
        tempDto.setIsBorrow(bookInfo.getBorrowReaderId() != null ? 1 : 0);
        tempDto.setIsReserve((bookInfo.getBorrowReaderId() == null && bookInfo.getReserveReaderId() != null && (bookInfo.getReserveDate() + 14400 * 1000 >= System.currentTimeMillis())) ? 1 : 0);
        tempDto.setDamage(bookInfo.getDamage());
        tempDto.setLost(bookInfo.getLost());
        return tempDto;

    }

}
